home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / gfx / edit / AmiCAD_2.07.lha / AmiCAD / ARexx / ImportTexte.AmiCAD < prev    next >
Text File  |  2000-11-10  |  3KB  |  133 lines

  1. /* Importation d'un texte dans une zone rectangulaire
  2.    Version 1.00: 26 avril 1998
  3.    Version 1.01: 3 Février 1999 (correction bug guillemets + gestion ligne)
  4.    Version 1.02: 21 février 1999 (modif appel REQFILE)
  5.    Version 1.03: 5 Janvier 2000 (utilisation GETZONE, traitement coupure lignes trop longues)
  6.    Version 1.04: 13 avril 2000 (adaptation version 205)
  7.    Version 1.05: 10 novembre 2000 (localisation anglais/français)
  8.    $VER: ImportTexte 1.05 (© R.Florac, 10 novembre 2000)
  9.    Bug: ne gère pas les échelles et le mode placement courants */
  10.  
  11. options results
  12.  
  13. signal on error
  14. signal on syntax
  15.  
  16. 'LANGUAGE'
  17. if result="français.language" then fr=1
  18. else fr=0
  19.  
  20. xg=-1; xd=0; yh=0; yb=0
  21. 'MODE_TRACÉ=DRAWMODE(-1):ROTATE(0,0):SYMMETRY(0,0):SETSCALE(0,100,100):FIRSTSEL'; obj=result
  22. if obj>0 then do
  23.     'TYPE('obj')'
  24.     if result=22 then do
  25.     'NEXTSEL('obj')'
  26.     if result=0 then do
  27.         'COORDS('obj')';
  28.         PARSE VAR result x0 ',' y0 ',' x1 ',' y1
  29.         xg=minima(x0,x1); xd=maxima(x0,x1)
  30.         yh=minima(y0,y1); yb=maxima(y0,y1)
  31.     end
  32.     end
  33. end
  34.  
  35. if xg=-1 then do
  36.     if fr=1 then 'GETZONE("Dessinez la zone où placer le texte")'
  37.     else 'GETZONE("Draw the box where you want to place the text")'
  38.     z=result
  39.     if z="" then exit
  40.     PARSE VAR z x0 ',' y0 ',' x1 ',' y1
  41.     xg=minima(x0,x1); xd=maxima(x0,x1)
  42.     yh=minima(y0,y1); yb=maxima(y0,y1)
  43. end
  44.  
  45. if fr=1 then 'REQFILE("Nom du fichier texte?", "Travail:texte/ASCII", "")'
  46. else 'REQFILE("Name of the text file?", "Work:Text/ASCII", "")'
  47. fichier=result
  48. y0=yh
  49. if fichier ~= "" then do
  50.     if open(file, fichier, 'R') then do
  51.     y0=y0+10
  52.     'SAVEALL'
  53.     do while ~eof(file)
  54.         ligne=readln(file)
  55.         if ligne ~= "" then do
  56.         ligne=translate(ligne,"        ",'09'x)
  57.         ligne=doublage_guillemets(ligne)
  58.         t=words(ligne)
  59.         p=1
  60.         n=t
  61.         if t=1 then do        /* il y a un seul mot à écrire */
  62.             'WRITE("'ligne'",'xg','y0')'
  63.             call ligne_suivante
  64.         end
  65.         else
  66.         do while p<=t
  67.             mot=subword(ligne,p,n)
  68.             'TXWIDTH("'mot'")'
  69.             l=result
  70.             if l>=xd-xg then do
  71.             n=n-1
  72.             end
  73.             else do
  74.             'WRITE("'mot'",'xg','y0')'
  75.             call ligne_suivante
  76.             p=p+n
  77.             n=t-n
  78.             end
  79.         end
  80.         end
  81.     end
  82.     close(file)
  83.     end
  84. end
  85. 'DRAWMODE(MODE_TRACÉ)'
  86. exit
  87.  
  88. ligne_suivante:
  89.     y0=y0+10
  90.     if y0>=yb then do
  91.     if fr=1 then 'MESSAGE("Zone trop petite pour"+CHR(10)+"placer tout le texte")'
  92.     else 'MESSAGE("The defined box is too small"+CHR(10)+"to place all the text")'
  93.     close(file)
  94.     'DRAWMODE(MODE_TRACÉ)'
  95.     exit
  96.     return
  97.  
  98. minima: procedure
  99.     parse arg v1,v2
  100.     if v1<v2 then return v1
  101.     return v2
  102. end
  103.  
  104. maxima: procedure
  105.     parse arg v1,v2
  106.     if v1>v2 then return v1
  107.     return v2
  108. end
  109.  
  110. doublage_guillemets: procedure
  111.     parse arg chaine
  112.     t=''
  113.     do i=1 to length(chaine)
  114.     c = substr(chaine,i,1)
  115.     if c='"' then c=c||'"'
  116.     t=t||c
  117.     end
  118.     return t
  119.  
  120. /* Traitement des erreurs, interruption du programme */
  121. syntax:
  122. erreur=RC
  123. if fr=1 then 'MESSAGE("Script ImportTexte.AmiCAD"+CHR(10)+"Erreur de syntaxe"+CHR(10)+"en ligne 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  124. else 'MESSAGE("ImportTexte.AmiCAD script"+CHR(10)+"Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  125. 'DRAWMODE(MODE_TRACÉ)'
  126. exit
  127.  
  128. error:
  129. if fr=1 then 'MESSAGE("Script ImportTexte"+CHR(10)+"Erreur en ligne 'SIGL'")'
  130. else 'MESSAGE("ImportTexte.AmiCAD Script"+CHR(10)+"Error in line 'SIGL'")'
  131. 'DRAWMODE(MODE_TRACÉ)'
  132. exit
  133.